from django.db import models

# Create your models here.
from django.utils import timezone

from apps.users.models import Users


class Category(models.Model):
    '''文章一级分类'''
    name=models.CharField(max_length=50,verbose_name='分类名称')

    class Meta:
        db_table='tb_Category'
        verbose_name='文章一级分类'
        verbose_name_plural=verbose_name

    def __str__(self):
        return self.name

class Tags(models.Model):
    """文章标签"""
    name=models.CharField(max_length=50,verbose_name='标签名称')

    class Meta:
        db_table='tb_Tags'
        verbose_name='文章标签'

    def __str__(self):
        return self.name

class Article(models.Model):
    """文章详情"""
    title=models.CharField(max_length=50,verbose_name='文章标题')
    content=models.TextField()# the article content
    category=models.ForeignKey(Category,on_delete=models.CASCADE,verbose_name='文章分类')
    views = models.PositiveIntegerField(default=0, editable=False,verbose_name='文章浏览量')
    # comments=models.TextField()#文章评论
    date=models.DateField(default=timezone.now)
    tag=models.ForeignKey(Tags,on_delete=models.PROTECT,verbose_name='文章标签')
    article_use=models.ForeignKey(Users,on_delete=models.CASCADE,verbose_name='文章发布者')

    class  Meta:
        db_table='tb_Article'
        verbose_name='文章详情'
        verbose_name_plural=verbose_name

    class Media:
        js = (
            '/static/js/kindeditor/kindeditor-all-min.js',
            '/static/js/kindeditor/kindeditor-all.js',
            '/static/js/kindeditor/config.js',)



    def __str__(self):
        return "文章"+self.title



class IPADDR(models.Model):
    '''IP'''
    name=models.CharField(max_length=50,verbose_name='IP')
    ip_article=models.ForeignKey(Article,on_delete=models.CASCADE,verbose_name='文章IP访问')
    time=models.FloatField(default=0)
    class Meta:
        db_table='tb_IP'
        verbose_name='IP_ADDRESS'
        verbose_name_plural=verbose_name

    def __str__(self):
        return 'IP地址:'+self.name